<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("lib/my_library.php");
require_once("Writer.php");
//Includes
use_unit("components4phpfull/jtpagecontrol.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class check_reminder extends Page
{
       public $lblmodel = null;
       public $lblmake = null;
       public $Label43 = null;
       public $Label38 = null;
       public $lblyear = null;
       public $lblplate = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $edSearchComp = null;
       public $btnSearchComp = null;
       public $edtSearch = null;
       public $btnSearch = null;
       public $JTComplete = null;
       public $imageAddReminder = null;
       public $btnExport = null;
       public $JTReminderList = null;
       public $JTCheckRemindHidden = null;
       public $JTPageControl1 = null;
       public $lbldate = null;
       public $Label1 = null;
       public $lblcap = null;
       public $lblmil = null;
       public $JTGroupBox1 = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $Image1 = null;
       public $Label48 = null;
       public $lblVeh = null;
       public $imgBack = null;
       public $Image4 = null;
       public $JTSiteTheme1 = null;
       public $hiddenVeh = null;
       function btnExportJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel.png"
       <?php

       }

       function btnExportJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnExport'].src="image/excel2.png"
       <?php

       }


       function btnSearchCompClick($sender, $params)
       {
       redirect('check_reminder.php?veh='.$this->hiddenVeh->getValue().'&layer=1');


       }

       function edSearchCompJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edSearchComp').value = '';
       <?php

       }


       function JTCompleteShow($sender, $params)
       {
        $my_lib = new my_library();
        $query_check = "select * from veh_reminder_tbl where vehicle_id='".$this->hiddenVeh->getValue()."' and (due_hours like '%".$this->edSearchComp->Text."%'
        or due_date like '%".$this->edSearchComp->Text."%'
        or type like '%".$this->edSearchComp->Text."%'
        or description like '%".$this->edSearchComp->Text."%'
        or status2 like '%".$this->edSearchComp->Text."%'
        or schedule_by like '%".$this->edSearchComp->Text."%') and status2='Complete' order by reminder_id ASC";
        $result_check = mysql_query($query_check)or die(mysql_error());

        $query_od = "select * from vehicle_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenVeh->getValue()."'";
        $result_od = mysql_query($query_od)or die(mysql_error());
        $row_od = mysql_fetch_array($result_od);
        $arr = array();
        while($row_check = mysql_fetch_array($result_check))
          {
            $reminder_id = $row_check['reminder_id'];
            $completion = $row_check['completion_window'];

            $vehicle_id = $row_check['vehicle_id'];
            $due_date = $row_check['due_date'];
            $curr_date = date("Y-m-d");
            $odometer = $row_check['due_hours'];
            $curr_od = $row_od['curr_tracking_value'];
            $curr_hr = $row_od['curr_hours'];
            $track_by = $row_check['schedule_by'];
            $prev_od = $row_od['tracking_value'];
            $prev_hr = $row_od['start_hours'];

            if($due_date!=null || $due_date!='')
            $days_diff = $my_lib->daysDifference($due_date, $curr_date);


            $veh_track = $row_od['track_by'];

            if($veh_track=='distance')
            {
            $odometer_diff = $odometer - $curr_od;
            $mileage = $curr_od - $prev_od;
            }

            if($veh_track=='hours')
            {
            $odometer_diff = $odometer - $curr_hr;
            $mileage = $curr_od - $prev_hr;
            }



            $sched_list = $row_check['schedule_by'];
            if($sched_list=='Date' || $sched_list=='Time')
            {
            $due = $row_check['due_date'];
            }
            if($sched_list=='Hours')
            {
            $due = $row_check['due_hours'].' '.'hours';
            }
            if($sched_list=='Mileage')
            {
            $due = $row_check['due_hours'].' '.'Km';
            }


            if($track_by=='Hours' || $track_by=='Mileage')
            {
              $rem_odom_red = $row_check['rem_hours'];
              $rem_odom_green = $rem_odom_red * 2;
              $rem_odom_yellow = $rem_odom_green - ($rem_odom_red/2);
            }
            else if($track_by=='Date' || $track_by=='Time')
            {
              $rem_by = $row_check['rem_by'];
              $rem_time_red = $row_check['rem_time'];
              if($rem_by=='Months')
              $rem_time_red = $rem_time_red * 30;

              $rem_time_green = $rem_time_red * 2;
              $rem_time_yellow = $rem_time_green - ($rem_time_red/2);
            }


            //die(var_dump($row_check));
            //if($track_by=='Both' && ($curr_date>=$due_date || $curr_od>=$odometer))
            if($track_by=='Both')
            {
               if($days_diff>$rem_time_yellow && $odometer_diff>$rem_odom_yellow)
               $gauge = "<img src='image/gauge_green.png'/>";
               if(($days_diff<=$rem_time_yellow && $days_diff>$rem_time_red) || ($odometer_diff<=$rem_odom_yellow && $odometer_diff>$rem_odom_red))
               $gauge = "<img src='image/gauge_yellow.png'/>";
               if($days_diff<=$rem_time_red || $odometer_diff<=$rem_odom_red)
               $gauge = "<img src='image/gauge_red.png'/>";

               if($row_check['status2']=="Complete")
               {
               $color = "Silver";
               $tools = "";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete'>";
               }

               $arr[] = array(
               //'Alert Meter' => $gauge,
               'Scheduled by' => "<p style='color:".$color."'>".$row_check['schedule_by']."</p>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'No. of times rescheduled' => "<p style='color:".$color."'>".$row_check['times_resched']."</p>"
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>"
               );
            }
            //if($track_by=='Hours/Km' && $curr_od>=$odometer)
            if($track_by=='Hours/Km' || $track_by=='Hours' || $track_by=='Mileage')
            {
               if($odometer_diff>$rem_odom_yellow)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_green.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($odometer_diff<=$rem_odom_yellow && $odometer_diff>$rem_odom_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_yellow.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($odometer_diff<=$rem_odom_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_red.png' title='edit' border='0' cursor='pointer'/></a></div>";


               if($row_check['status2']=="Complete")
               {
               $color = "Silver";
               $tools = "<img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete'>";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";

               //<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/resched.png' title='Reschedule Reminder' border='0' cursor='pointer'/></a></div>

               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete'>";
               }

               $view = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";

               $arr[] = array(
               //'Alert Meter' => $gauge,
               'Scheduled by' => "<p style='color:".$color."'>".$row_check['schedule_by']."</p>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'No. of times rescheduled' => "<p style='color:".$color."'>".$row_check['times_resched']."</p>",
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'Tools' => $view
               );
            }
            //if($track_by=='Date' && $curr_date>=$due_date)
            if($track_by=='Date' || $track_by=='Time')
            {
               if($days_diff>$rem_time_yellow)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_green.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($days_diff<=$rem_time_yellow && $days_diff>$rem_time_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_yellow.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($days_diff<=$rem_time_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_red.png' title='edit' border='0' cursor='pointer'/></a></div>";

               $edit = "<img onclick=veh_reminder_edit.php?veh=".$vehicle_id."&reminder=".$row['reminder_id']." src=".$gauge." title='edit'>";

               if($row_check['status2']=="Complete")
               {
               $color = "Silver";
               $tools = "<img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete'>";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete'>";
               }

               $view = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";

               $arr[] = array(
               //'Alert Meter' => $gauge,
               'Scheduled by' => "<p style='color:".$color."'>".$row_check['schedule_by']."</p>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'No. of times rescheduled' => "<p style='color:".$color."'>".$row_check['times_resched']."</p>",
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'Tools' => $view
               );
            }
          }
            //die(var_dump($arr));
            $this->JTComplete->setCellData($arr);


       }

       function imageAddReminderJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imageAddReminder'].src="image/add_new.png"
       <?php

       }

       function imageAddReminderJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imageAddReminder'].src="image/add_new_blue.png"
       <?php

       }

       function btnSearchClick($sender, $params)
       {
       redirect('check_reminder.php?veh='.$this->hiddenVeh->getValue());
       }

       function btnSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       return false;
       <?php

       }

       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function btnExportClick($sender, $params)
       {
       $this->JTCheckRemindHidden->exportGridToXLSDownload('reminder_list.xls');
       }

       function JTCheckRemindHiddenShow($sender, $params)
       {
        $my_lib = new my_library();
        $query_check = "select * from veh_reminder_tbl where vehicle_id='".$this->hiddenVeh->getValue()."' and status2='Pending' order by reminder_id ASC";
        $result_check = mysql_query($query_check)or die(mysql_error());

        $query_od = "select * from vehicle_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenVeh->getValue()."'";
        $result_od = mysql_query($query_od)or die(mysql_error());
        $row_od = mysql_fetch_array($result_od);


       $arr = array();


       $arr[] = array(
                        '1' => 'Plate Num:'.' '.$row_od['veh_num'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''
                    );

       $arr[] = array(
                        '1' => 'Year:'.' '.$row_od['year'],
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );

       $arr[] = array(
                        '1' => 'Make:'.' '.$row_od['manufacturer_name'],
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );

       $arr[] = array(
                        '1' => 'Model:'.' '.$row_od['model_name'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );

       $arr[] = array(
                        '1' => 'Type/Style:'.' '.$row_od['style_name'],
                        '2'=> ' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );

       $arr[] = array(
                        '1' => ' ',
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );

       $arr[] = array(
                        '1' => 'LIST OF PENDING REMINDERS',
                        '2'=>' ',
                        '3' => ' ',
                        '4' => ' ',
                        '5' => ' ',
                        '6' =>'',
                        '7' =>''

                    );


        $arr[] = array(
      '1'=> 'Scheduled by',
      '2' => 'Due',
      '3' => 'Type',
      '4' => 'Description',
      '5' => 'Status',
      '6' =>'Alert Meter',
      '7' =>'No. of times rescheduled'
      );









        while($row_check = mysql_fetch_array($result_check))
          {

            $vehicle_id = $row_check['vehicle_id'];
            $due_date = $row_check['due_date'];
            $curr_date = date("Y-m-d");
            $odometer = $row_check['due_hours'];
            $curr_od = $row_od['curr_tracking_value'];
            $track_by = $row_check['schedule_by'];
            $prev_od = $row_od['tracking_value'];

            if($due_date!=null || $due_date!='')
            $days_diff = $my_lib->daysDifference($due_date, $curr_date);

            $odometer_diff = $odometer - $curr_od;
            $mileage = $curr_od - $prev_od;

            $scheduled_by = $row_check['schedule_by'];
            if($scheduled_by=='Hours')
            {
            $lbl = 'Hrs';
            }

            if($scheduled_by=='Km' || $scheduled_by=='Mileage')
            {
            $lbl = 'Km';
            }

            //if($track_by=='Both' && ($curr_date>=$due_date || $curr_od>=$odometer))
            if($track_by=='Both')
            {
               if($days_diff>14 && $odometer_diff>1000)
               $gauge = " ";
               if(($days_diff<=14 && $days_diff>7) || ($odometer_diff<=1000 && $odometer_diff>250))
               $gauge = "warning!";
               if($days_diff<=7 || $odometer_diff<=250)
               $gauge = "due!";

               $arr[] = array(
               '1' => $row_check['schedule_by'],
               '2' => $row_check['due_date'],
               '3' => $row_check['type'],
               '4' => $row_check['description'],
               '5' => $row_check['status2'],
               '6' => $gauge,
               '7' => $row_check['times_resched']
               );

              // die(var_dump($arr));
            }
            //if($track_by=='Hours/Km' && $curr_od>=$odometer)
            if($track_by=='Hours/Km' || $track_by=='Mileage' || $track_by=='Hours')
            {
               if($odometer_diff>1000)
               $gauge = " ";
               if($odometer_diff<=1000 && $odometer_diff>250)
               $gauge = "warning!";
               if($odometer_diff<=250)
               $gauge = "due!";

               $arr[] = array(
               '1' => $row_check['schedule_by'],
               '2' => $row_check['due_hours'].$lbl,
               '3' => $row_check['type'],
               '4' => $row_check['description'],
               '5' => $row_check['status2'],
               '6' => $gauge,
               '7' => $row_check['times_resched']
               );
            }
            //if($track_by=='Date' && $curr_date>=$due_date)
            if($track_by=='Date' || $track_by=='Time')
            {
               if($days_diff>14)
               $gauge = " ";
               if($days_diff<=14 && $days_diff>7)
               $gauge = "warning!";
               if($days_diff<=7)
               $gauge = "due!";

               $arr[] = array(
                '1' => $row_check['schedule_by'],
               '2' => $row_check['due_date'],
               '3' => $row_check['type'],
               '4' => $row_check['description'],
               '5' => $row_check['status2'],
               '6' => $gauge,
               '7' => $row_check['times_resched']
               );
            }
          }
            $this->JTCheckRemindHidden->setCellData($arr);


       }

       function check_reminderCreate($sender, $params)
       {
       $veh = $_GET['veh'];

       if($veh!=null && $veh!='')
       $this->hiddenVeh->setValue($veh);

       $this->JTPageControl1->TabIndex = $_GET['layer'];

       $this->imgBack->setLink('vehicle_list.php?company='.$_SESSION['company_id']);
       $this->imageAddReminder->setLink('veh_reminder_create2.php?veh='.$this->hiddenVeh->getValue());

      if($_SESSION['access_vehicle']==1)
       {
       $this->imageAddReminder->Visible=false;
       $this->btnExport->Left=948;
       }

       if($_SESSION['access_vehicle']==2)
       {
       $this->imageAddReminder->Visible=true;
       $this->btnExport->Left=846;
       }


      $result_vin = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='" .$this->hiddenVeh->getValue(). "'");
      $row_selected = mysql_fetch_array($result_vin);
      $label = $row_selected['VIN'];
      $this->lblVeh->Caption = $label;
      $this->lblyear->Caption = $row_selected['year'];
      $this->lblmake->Caption = $row_selected['manufacturer_name'];
      $this->lblmodel->Caption = $row_selected['model_name'];
      $this->lblplate->Caption = $row_selected['veh_num'];
      $this->lbldate->Caption = date('Y-m-d');

      if($row_selected['track_by']=='distance')
      {
      $this->lblcap->Caption = 'Mileage:';
      $this->lblmil->Caption = $row_selected['curr_tracking_value'];
      }
      if($row_selected['track_by']=='hours')
      {
      $this->lblcap->Caption = 'Hours:';
      $this->lblmil->Caption = $row_selected['curr_hours'];
      }


       }

       function JTReminderListShow($sender, $params)
       {
        $my_lib = new my_library();
        $query_check = "select * from veh_reminder_tbl where vehicle_id='".$this->hiddenVeh->getValue()."' and (due_hours like '%".$this->edtSearch->Text."%'
        or due_date like '%".$this->edtSearch->Text."%'
        or type like '%".$this->edtSearch->Text."%'
        or description like '%".$this->edtSearch->Text."%'
        or status2 like '%".$this->edtSearch->Text."%') and status2='Pending' order by reminder_id ASC";
        $result_check = mysql_query($query_check)or die(mysql_error());

        $query_od = "select * from vehicle_tbl where company_id='".$_SESSION['company_id']."' and vehicle_id='".$this->hiddenVeh->getValue()."'";
        $result_od = mysql_query($query_od)or die(mysql_error());
        $row_od = mysql_fetch_array($result_od);
        $arr = array();
        while($row_check = mysql_fetch_array($result_check))
          {
            $reminder_id = $row_check['reminder_id'];
            $completion = $row_check['completion_window'];

            $vehicle_id = $row_check['vehicle_id'];
            $due_date = $row_check['due_date'];
            $curr_date = date("Y-m-d");
            $odometer = $row_check['due_hours'];
            $curr_od = $row_od['curr_tracking_value'];
            $curr_hr = $row_od['curr_hours'];
            $track_by = $row_check['schedule_by'];
            $prev_od = $row_od['tracking_value'];
            $prev_hr = $row_od['start_hours'];

            if($due_date!=null || $due_date!='')
            $days_diff = $my_lib->daysDifference($due_date, $curr_date);


            $veh_track = $row_od['track_by'];

            if($veh_track=='distance')
            {
            $odometer_diff = $odometer - $curr_od;
            $mileage = $curr_od - $prev_od;
            }

            if($veh_track=='hours')
            {
            $odometer_diff = $odometer - $curr_hr;
            $mileage = $curr_od - $prev_hr;
            }



            $sched_list = $row_check['schedule_by'];
            if($sched_list=='Date' || $sched_list=='Time')
            {
            $due = $row_check['due_date'];
            }
            if($sched_list=='Hours')
            {
            $due = $row_check['due_hours'].' '.'hours';
            }
            if($sched_list=='Mileage')
            {
            $due = $row_check['due_hours'].' '.'Km';
            }


            if($track_by=='Hours' || $track_by=='Mileage')
            {
              $rem_odom_red = $row_check['rem_hours'];
              $rem_odom_green = $rem_odom_red * 2;
              $rem_odom_yellow = $rem_odom_green - ($rem_odom_red/2);
            }
            else if($track_by=='Date' || $track_by=='Time')
            {
              $rem_by = $row_check['rem_by'];
              $rem_time_red = $row_check['rem_time'];
              if($rem_by=='Months')
              $rem_time_red = $rem_time_red * 30;

              $rem_time_green = $rem_time_red * 2;
              $rem_time_yellow = $rem_time_green - ($rem_time_red/2);
            }

             $recur = $row_check['recur_per_veh'];
             if($recur=='1')//if($recur=='1'||$row_check['recurring_id']!='0')
             {
             $icon = "<img src=image/recur3.png title='Recurring'></img>";
             }
             if($recur=='0')//if($recur=='0'&&$row_check['recurring_id']=='0')
             {
             $icon = "";
             }
            //die(var_dump($row_check));
            //if($track_by=='Both' && ($curr_date>=$due_date || $curr_od>=$odometer))
            if($track_by=='Both')
            {
               if($days_diff>$rem_time_yellow && $odometer_diff>$rem_odom_yellow)
               $gauge = "<img src='image/gauge_green.png'/>";
               if(($days_diff<=$rem_time_yellow && $days_diff>$rem_time_red) || ($odometer_diff<=$rem_odom_yellow && $odometer_diff>$rem_odom_red))
               $gauge = "<img src='image/gauge_yellow.png'/>";
               if($days_diff<=$rem_time_red || $odometer_diff<=$rem_odom_red)
               $gauge = "<img src='image/gauge_red.png'/>";

               if($row_check['status2']=="Complete")
               {
               $color = "Silver";
               $tools = "";
               }

               if($row_check['status2']=="Pending")
               {
               $color = "Black";

               if($_SESSION['access_vehicle']==1)
               {
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>";
               }

               if($_SESSION['access_vehicle']==2)
               {
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
               }

               }

               $arr[] = array(
               'Alert Meter' => $gauge,
               'Scheduled by' => $icon.' '."<font style='color:".$color."'>".$row_check['schedule_by']."</font>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>"
               );
            }
            //if($track_by=='Hours/Km' && $curr_od>=$odometer)
            if($track_by=='Hours/Km' || $track_by=='Hours' || $track_by=='Mileage')
            {
               if($odometer_diff>$rem_odom_yellow)
               //$gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_green.png' title='edit' border='0' cursor='pointer'/></a></div>";
               $gauge = "<div align='center'><img src='image/gauge_green.png' border='0' cursor='pointer'/></div>";
               if($odometer_diff<=$rem_odom_yellow && $odometer_diff>$rem_odom_red)
               //$gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_yellow.png' title='edit' border='0' cursor='pointer'/></a></div>";
               $gauge = "<div align='center'><img src='image/gauge_yellow.png' border='0' cursor='pointer'/></div>";
               if($odometer_diff<=$rem_odom_red)
               //$gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_red.png' title='edit' border='0' cursor='pointer'/></a></div>";
               $gauge = "<div align='center'><img src='image/gauge_red.png' border='0' cursor='pointer'/></div>";


               // START COMPLETE
               if($row_check['status2']=="Complete")
               {
               $color = "Silver";

               if($_SESSION['access_vehicle']==1)
               {
               $tools = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";
               }

               if($_SESSION['access_vehicle']==2)
               {
               $tools = "<img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
               }

               }
               // END COMPLETE


               // START PENDING
               if($row_check['status2']=="Pending")
               {
               $color = "Black";

               //<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/resched.png' title='Reschedule Reminder' border='0' cursor='pointer'/></a></div>
               if($_SESSION['access_vehicle']==1)
               {
               $tools = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";
               }

               if($_SESSION['access_vehicle']==2)
               {
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
               }
               }
               // END COMPLETE

               $arr[] = array(
               'Alert Meter' => $gauge,
               'Scheduled by' => $icon.' '."<font style='color:".$color."'>".$row_check['schedule_by']."</font>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'No. of times rescheduled' => "<p style='color:".$color."'>".$row_check['times_resched']."</p>",
               'Tools' => $tools
               );
            }
            //if($track_by=='Date' && $curr_date>=$due_date)
            if($track_by=='Date' || $track_by=='Time')
            {
               /*if($days_diff>$rem_time_yellow)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_green.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($days_diff<=$rem_time_yellow && $days_diff>$rem_time_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_yellow.png' title='edit' border='0' cursor='pointer'/></a></div>";
               if($days_diff<=$rem_time_red)
               $gauge = "<div align='center'><a href=veh_reminder_edit2.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/gauge_red.png' title='edit' border='0' cursor='pointer'/></a></div>";
               */

               if($days_diff>$rem_time_yellow)
               $gauge = "<div align='center'><img src='image/gauge_green.png' border='0' cursor='pointer'/></div>";
               if($days_diff<=$rem_time_yellow && $days_diff>$rem_time_red)
               $gauge = "<div align='center'><img src='image/gauge_yellow.png' border='0' cursor='pointer'/></div>";
               if($days_diff<=$rem_time_red)
               $gauge = "<div align='center'><img src='image/gauge_red.png' border='0' cursor='pointer'/></div>";


               $edit = "<img onclick=veh_reminder_edit.php?veh=".$vehicle_id."&reminder=".$row['reminder_id']." src=".$gauge." title='edit'>";

               // START COMPLETE
               if($row_check['status2']=="Complete")
               {
               $color = "Silver";

               if($_SESSION['access_vehicle']==2)
               {
               $tools = "<img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
               }

               if($_SESSION['access_vehicle']==1)
               {
               $tools = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";
               }
               }
               // END COMPLETE


               // START PENDING
               if($row_check['status2']=="Pending")
               {
               $color = "Black";

               if($_SESSION['access_vehicle']==2)
               {
               $tools = "<img onclick=pop_resched('".$this->hiddenVeh->getValue()."','".$reminder_id."'); src='image/resched.png' title='Reschedule Reminder' style='cursor:pointer'>
               <img onclick=pop_close('".$this->hiddenVeh->getValue()."','".$reminder_id."','".$completion."'); src='image/complete.png' title='Complete Reminder' style='cursor:pointer'>
               <img onclick=js_deleteReminder('".$vehicle_id."','".$reminder_id."'); src='image/delete.png' title='delete' style='cursor:pointer'>";
               }

               if($_SESSION['access_vehicle']==1)
               {
               $tools = "<div align='left'><a href=veh_reminder_view.php?veh=".$vehicle_id."&reminder=".$reminder_id."><img src='image/view.png' title='View Reminder' border='0' cursor='pointer'/></a></div>";
               }
               }
               // END PENDING

               $arr[] = array(
               'Alert Meter' => $gauge,
               'Scheduled by' => $icon.' '."<font style='color:".$color."'>".$row_check['schedule_by']."</font>",
               'Due' => "<p style='color:".$color."'>".$due."</p>",
               //'Mileage(km)' =>"<p style='color:".$color."'>".$mileage."</p>",
               //'Reminder Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               'Type' => "<p style='color:".$color."'>".$row_check['type']."</p>",
               'Description' => "<p style='color:".$color."'>".$row_check['description']."</p>",
               //'Due at(km/hrs)' => "<p style='color:".$color."'>".$row_check['due_hours']."</p>",
               //'Due by' => "<p style='color:".$color."'>".$row_check['due_date']."</p>",
               //'Status' => "<p style='color:".$color."'>".$row_check['status2']."</p>",
               'No. of times rescheduled' => "<p style='color:".$color."'>".$row_check['times_resched']."</p>",
               'Tools' => $tools
               );
            }
          }
            //die(var_dump($arr));
            $this->JTReminderList->setCellData($arr);


       }

}

global $application;

global $check_reminder;

//Creates the form
$check_reminder=new check_reminder($application);

//Read from resource file
$check_reminder->loadResource(__FILE__);

//Shows the form
$check_reminder->show();

?>